package com.situ.web.service.impl;

import com.situ.web.dao.IStudentDao;
import com.situ.web.dao.impl.StudentDaoImpl;
import com.situ.web.pojo.Student;
import com.situ.web.service.IStudentService;
import com.situ.web.util.PageInfo;

import java.util.List;

public class StudentServiceImpl implements IStudentService {
    private IStudentDao studentDao = new StudentDaoImpl();

    @Override
    public List<Student> selectAll() {
        return studentDao.selectAll();
    }

    @Override
    public void deleteById(Integer id) {
        studentDao.deleteById(id);
    }

    @Override
    public void add(Student student) {
        studentDao.add(student);
    }

    @Override
    public PageInfo selectByPage(int pageNo, int pageSize) {
        int offset = (pageNo - 1) * pageSize;
        //调用dao得到当前页的数据
        List<Student> list = studentDao.selectByPage(offset, pageSize);
        //调用dao查询总的数量
        int totalCount = studentDao.selectTotalCount();
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);

        return new PageInfo(pageNo, pageSize, totalPage, list);
    }

    public static void main(String[] args) {
        int totalCount = 12;
        int pageSize = 5;
        int totalPage = (int)Math.ceil((double) totalCount / pageSize);
    }


}
